package com.hefeng.unit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hefeng.common.core.web.domain.AjaxResult;
import com.hefeng.unit.controller.entity.ParamEntity;
import com.hefeng.unit.domain.GyUserOrder;
import com.hefeng.unit.service.GyUserOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "用户工单信息表对象功能接口")
@RestController
@RequestMapping("/unit/gyDeviceOrder")
public class GyUserOrderController {
    @Autowired
    private GyUserOrderService gyUserOrderService;
    /**
     * 方法说明:获取工单分页记录
     * @param paramEntity
     * @return null
     * @Author: fu
     */
    @RequestMapping(value = "/getOrderPage",produces = "application/json;charset=UTF-8")
    @ApiOperation("获取工单分页列表")
    public AjaxResult getOrderPage(@RequestBody ParamEntity paramEntity){
        Map<String,Object> dataMap=new HashMap<>();
        GyUserOrder gyUserOrder =new GyUserOrder();
        gyUserOrder.setUserId(Long.parseLong(paramEntity.getUserId()));
        Page<GyUserOrder> page=gyUserOrderService.getOrderPage(gyUserOrder,paramEntity.getPage(), paramEntity.getPageSize());
        return AjaxResult.success("获取工单列表成功！",page);
    }

    /**
     *
     * @param gyUserOrder
     * @return fwb
     */
    @RequestMapping(value = "/saveOrder",produces = "application/json;charset=UTF-8")
    @ApiOperation("保存工单信息")
    public AjaxResult seveOrder(@RequestBody GyUserOrder gyUserOrder){
        Map<String,Object> dataMap=new HashMap<>();
        dataMap=gyUserOrderService.insert(gyUserOrder);
        if(!dataMap.get("make").equals(true)){
            return AjaxResult.error(501,dataMap.get("msg").toString());
        }
        return AjaxResult.success("保存工单成功！",dataMap);
    }


}
